package com.hzqy.persistence.dao.hqjc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.WchatOrderVo;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.SysProductVo;
import com.hzqy.web.vo.UserBillVo;

@Repository
public class PayDao extends PersistenceDao<PmsUserVo, Integer>{
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	public SysProductVo selectProduct(int f_sp_id) {
		return getSqlSession().selectOne(this.getNamespace() + "selectProduct", f_sp_id);
	}
	
	public SysProductVo selectProductByCode(String f_sp_productcode) {
		return getSqlSession().selectOne(this.getNamespace() + "selectProductByCode", f_sp_productcode);
	}
	
	public int insertUserBill(UserBillVo userBillVo) {
		return getSqlSession().insert(this.getNamespace() + "insertUserBill", userBillVo);
	}
	
	/**
	 * 插入退订记录
	 * @param userBillVo
	 * @return
	 */
	public int insertUnsubBill(UserBillVo userBillVo){
		try{
			this.getSqlSession().update(this.getNamespace()+"updateUnsubBill",userBillVo);
			return 1;
		}catch(Exception e){
			LOG.error("插入退订记录失败",e);
			return 0;
		}
	}
	
	/**
	 * 查询最近一次订购记录
	 * @param userBillVo
	 * @return
	 */
	public UserBillVo selectCurUserBill(UserBillVo userBillVo){
		UserBillVo billVo = null;
		try{
			billVo = (UserBillVo) this.getSqlSession().selectOne(this.getNamespace()+"selectCurUserBill",userBillVo);
			return billVo;
		}catch(Exception e){
			LOG.error("查询最近一次订购记录失败",e);
			return null;
		}
	}
	
	/**
	 * 更新订购信息
	 * @param userBillVo
	 * @return
	 */
	public int updateUserBill(UserBillVo userBillVo){
		try{
			this.getSqlSession().update(this.getNamespace()+"updateUserBill",userBillVo);
			return 1;
		}catch(Exception e){
			LOG.error("插入退订记录失败",e);
			return 0;
		}
	}
	
	public WchatOrderVo selectWxOrder(WchatOrderVo wchatOrderVo){
		WchatOrderVo billVo = null;
		try{
			billVo = (WchatOrderVo) this.getSqlSession().selectOne(this.getNamespace()+"selectWxOrder",wchatOrderVo);
			return billVo;
		}catch(Exception e){
			LOG.error("查询支付记录失败",e);
			return null;
		}
	}
	
}
